Skip to content

Add Cache class for using WordPress built-in transients in more readable way#14

Open
onnimonni wants to merge 3 commits intogetherbert:devfrom
onnimonni:dev
Open

Add Cache class for using WordPress built-in transients in more readable way#14
onnimonni wants to merge 3 commits intogetherbert:devfrom
onnimonni:dev

Conversation

@onnimonni
Copy link
Copy Markdown
Contributor

Hello!

I just love to use transients for almost everything in WordPress. It enhances loading speeds significantly. But I'm always frustrated how ugly it looks:

if (false === ( $resources = get_transient( 'my-resources' ) ) ) {
    $resources = Resource::all($start,$end);
    set_transient( 'my-resources', $resources );
}

I used anonymous functions to create Cache class so you could refactor upper code example into:

$resources = Cache::store('my-resources',function() {
    return Resource::all($start,$end);
});

This should be familiar for all javascript guys using herbert.
This also respects Pragma: no-cache headers from the request.

There might be better and more readable ways than this but I'm adding it here as a suggestion.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants